package fun.sboy.headacheMemo.service.impl;

import fun.sboy.headacheMemo.entry.TaskTodoProgress;
import fun.sboy.headacheMemo.mapper.TaskTodoProgressMapper;
import fun.sboy.headacheMemo.service.TaskTodoProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskTodoProgressServiceImpl implements TaskTodoProgressService {

    @Autowired
    private TaskTodoProgressMapper taskTodoProgressMapper;

    @Override
    public void insertProgress(String taskId) {
        if (taskTodoProgressMapper.insertProgressByTaskId(taskId) == 0) {
            throw new RuntimeException("添加任务步骤记录失败！");
        }
    }

    @Override
    public void updateProgressByTaskId(TaskTodoProgress taskTodoProgress) {
        if (taskTodoProgressMapper.updateProgressByTaskId(taskTodoProgress) == 0) {
            throw new RuntimeException("更新任务步骤失败！");
        }
    }

    /**
     * 通过sql执行拼接，而不是进行修改
     *
     * @param taskTodoProgress
     */
    @Override
    public void updateProgressByTaskIdJoin(TaskTodoProgress taskTodoProgress) {
        if (taskTodoProgressMapper.updateProgressByTaskIdJoin(taskTodoProgress) == 0) {
            throw new RuntimeException("更新任务步骤失败！");
        }
    }

    @Override
    public TaskTodoProgress selectByTaskTodoId(String taskId) {
        return taskTodoProgressMapper.selectByTaskTodoId(taskId);
    }

    @Override
    public void deleteProgressByTaskId(String taskId) {
        if (taskTodoProgressMapper.deleteProgressByTaskId(taskId) == 0) {
            throw new RuntimeException("删除任务步骤记录失败！");
        }
    }
}
